//
// Decompiled by Jadx - 468ms
//
package r;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.activity.b;
import as.a;
import fi.e;
import fi.w;
import fn.y;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.regex.Pattern;
import me.plusne.MainActivity;
import me.plusne.NativeTools;
import me.plusne.common.Json.Login.JsonLoginUserInfo;
import me.plusne.common.Json.Soul.JsonSuccess;
import okhttp3.ae;
import okhttp3.af;
import s.a;

public final class g {
    public static String a(String str) {
        try {
            byte[] digest = MessageDigest.getInstance("MD5").digest(str.getBytes());
            StringBuilder sb = new StringBuilder();
            for (byte b : digest) {
                String hexString = Integer.toHexString(b & 255);
                if (hexString.length() < 2) {
                    sb.append(0);
                }
                sb.append(hexString);
            }
            return sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    public static void b(Activity activity, String str) {
        p(activity, "https://pay.nnnen.com/index.html#/?user=" + str);
    }

    public static int c(int i, int i2) {
        if (i == 0 && i2 == 0) {
            return 0;
        }
        return (new Random().nextInt(i2) % ((i2 - i) + 1)) + i;
    }

    public static void d(Activity activity) {
        if (y.by.getPre().equals("WX")) {
            Intent launchIntentForPackage = activity.getPackageManager().getLaunchIntentForPackage(activity.getPackageName());
            if (launchIntentForPackage != null) {
                launchIntentForPackage.addFlags(0x10008000);
                ((AlarmManager) activity.getSystemService("alarm")).set(0, System.currentTimeMillis() + 2000, PendingIntent.getActivity(activity, 0, launchIntentForPackage, 0x14000000));
                activity.finishAffinity();
                System.exit(0);
                return;
            }
            return;
        }
        ComponentName component = activity.getPackageManager().getLaunchIntentForPackage(activity.getPackageName()).getComponent();
        ComponentName componentName = new ComponentName("me.plusne", MainActivity.class.getName());
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putString("PackageName", activity.getPackageName());
        bundle.putString("ActivityClassName", component.getClassName());
        intent.putExtras(bundle);
        intent.setComponent(componentName);
        activity.startActivity(intent);
        activity.finishAffinity();
    }

    public static void e(Activity activity, boolean z) {
        if (z) {
            w wVar = new w(activity);
            wVar.bj(fi.e.MESSAGE);
            wVar.bi("重启提示");
            wVar.bc("利用拉起PlusNE主程序来重新启动 \"" + y.by.getAppName() + "\"");
            wVar.bg("重新启动");
            wVar.v = new a(activity, 1);
            wVar.bk();
            return;
        }
        d(activity);
    }

    public static String f(String str, String str2, String str3) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        try {
            int length = str2.length() + str.indexOf(str2);
            return str.substring(length, str.indexOf(str3, length));
        } catch (StringIndexOutOfBoundsException unused) {
            return null;
        }
    }

    public static boolean g(String str) {
        if (str == null || str.length() < 5 || str.length() > 12 || str.charAt(0) == '0') {
            return false;
        }
        for (int i = 0; i < str.length(); i++) {
            char charAt = str.charAt(i);
            if (charAt < '0' || charAt > '9') {
                return false;
            }
        }
        return true;
    }

    public static void h(Activity activity, String str) {
        if (activity == null) {
            return;
        }
        ((ClipboardManager) activity.getSystemService("clipboard")).setPrimaryClip(ClipData.newPlainText("content", str));
    }

    public static JsonLoginUserInfo i(String str) {
        String p;
        if (str == null || TextUtils.isEmpty(str) || (p = NativeTools.p(str)) == null) {
            return null;
        }
        return (JsonLoginUserInfo) b.c(p, JsonLoginUserInfo.class);
    }

    public static String j(String str) {
        Uri parse = Uri.parse(str);
        return parse.getScheme() + "://" + parse.getHost() + parse.getPath();
    }

    public static long k(String str) {
        long j = 0;
        if (str != null && !str.isEmpty()) {
            MediaPlayer mediaPlayer = new MediaPlayer();
            try {
                mediaPlayer.setDataSource(str);
                mediaPlayer.prepare();
                j = mediaPlayer.getDuration();
            } catch (IOException unused) {
            }
            mediaPlayer.stop();
            mediaPlayer.reset();
            mediaPlayer.release();
        }
        return j;
    }

    public static String l(String str, String str2) {
        return "<font color='" + str2 + "'>" + str + "</font>";
    }

    public static JsonSuccess m(String str) {
        if (!TextUtils.isEmpty(str)) {
            return (JsonSuccess) b.c(str, JsonSuccess.class);
        }
        return null;
    }

    public static String n() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis()));
    }

    public static String o() {
        return fn.b.g("check_token", "");
    }

    public static void p(Context context, String str) {
        context.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str)));
    }

    public static boolean q(String str, ArrayList arrayList) {
        if (arrayList == null || str == null || TextUtils.isEmpty(str)) {
            return false;
        }
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            if (it.next().equals(str)) {
                return true;
            }
        }
        return false;
    }

    public static boolean r(Activity activity) {
        List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = ((ActivityManager) activity.getSystemService("activity")).getRunningAppProcesses();
        if (runningAppProcesses == null) {
            return false;
        }
        String str = activity.getApplicationInfo().packageName;
        for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
            if (str.equalsIgnoreCase(runningAppProcessInfo.processName) && runningAppProcessInfo.importance == 100) {
                return true;
            }
        }
        return false;
    }

    public static boolean s(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        return Pattern.compile("^[0-9a-zA-Z]{6,16}$").matcher(str).matches();
    }

    public static boolean t(String str, List list) {
        if (TextUtils.isEmpty(str) || list == null) {
            return false;
        }
        Iterator it = list.iterator();
        while (it.hasNext()) {
            if (str.trim().contains(((fi.a) it.next()).getKey().trim())) {
                return true;
            }
        }
        return false;
    }

    public static String u(String str) {
        return Pattern.compile("\\[[^\\[\\]]*\\]").matcher(str).replaceAll("");
    }

    public static void v(ImageView imageView, int i) {
        Context context = imageView.getContext();
        Object obj = as.a.b;
        imageView.setColorFilter(a.d.a(context, i), PorterDuff.Mode.SRC_IN);
    }

    public static Spanned w(TextView textView, String str) {
        String replace;
        if (str == null) {
            replace = "";
        } else {
            String replace2 = str.replace("[新增]", "<font color='#27903A'>[新增]</font>").replace("[适配]", "<font color='#008FD5'>[适配]</font>").replace("[删除]", "<font color='#EE3B2F'>[删除]</font>").replace("[优化]", "<font color='#C9AE00'>[优化]</font>").replace("[修复]", "<font color='#F26A2F'>[修复]</font>");
            textView.setMovementMethod(LinkMovementMethod.getInstance());
            textView.setLinkTextColor(Color.parseColor("#5A9CF0"));
            replace = replace2.replace("\r\n", "<br />").replace("\n", "<br />");
        }
        return Html.fromHtml(replace, 0);
    }

    public static void x(ae aeVar, File file) {
        FileOutputStream fileOutputStream;
        af afVar = aeVar.h;
        InputStream byteStream = afVar.byteStream();
        FileOutputStream fileOutputStream2 = null;
        try {
            try {
                try {
                    fileOutputStream = new FileOutputStream(file);
                } catch (IOException e) {
                    e.printStackTrace();
                    return;
                }
            } catch (Exception e2) {
                e = e2;
            }
        } catch (Throwable th) {
            th = th;
            fileOutputStream = fileOutputStream2;
        }
        try {
            byte[] bArr = new byte[1024];
            afVar.contentLength();
            while (byteStream.read(bArr) != -1) {
                fileOutputStream.write(bArr);
            }
            byteStream.close();
            fileOutputStream.close();
        } catch (Exception e3) {
            e = e3;
            fileOutputStream2 = fileOutputStream;
            e.printStackTrace();
            byteStream.close();
            if (fileOutputStream2 != null) {
                fileOutputStream2.close();
            }
        } catch (Throwable th2) {
            th = th2;
            try {
                byteStream.close();
                if (fileOutputStream != null) {
                    fileOutputStream.close();
                }
            } catch (IOException e4) {
                e4.printStackTrace();
            }
            throw th;
        }
    }
}
